﻿/*******************************************************************************
 * Copyright © 2016
 * 
 * Description: MVC快速开发平台  FROM http://xmwxgn.com
 *
*********************************************************************************/
using ZFine.Code;
using ZFine.Domain.Entity.Gas;
using ZFine.Domain.IRepository.Gas;
using ZFine.Repository.Gas;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ZFine.Application.Gas
{
    public class DataShareConfigApp
    {
        private IDataShareConfigRepository service = new DataShareConfigRepository();

        /// <summary>
        /// 客户端插入
        /// </summary>
        /// <param name="dataShareConfigEntity"></param>
        public void ClientInsert(DataShareConfigEntity dataShareConfigEntity)
        {
            dataShareConfigEntity.ClientCreate();
            service.Insert(dataShareConfigEntity);
        }
        public List<DataShareConfigEntity> GetList(Pagination pagination)
        {
            var expression = ExtLinq.True<DataShareConfigEntity>();
            return service.FindList(expression, pagination);
        }
        public List<DataShareConfigEntity> GetList()
        {
            return service.IQueryable().OrderBy(t => t.F_CreatorTime).ToList();
        }
        /// <summary>
        /// 获得IQueryable
        /// </summary>
        /// <returns></returns>
        public List<DataShareConfigEntity> GetIQueryable(string ConfigName)
        {
            var expression = ExtLinq.True<DataShareConfigEntity>();
            if (!string.IsNullOrEmpty(ConfigName))
            {
                expression = expression.And(t => t.ConfigName == ConfigName);
            }
            return service.IQueryable(expression).ToList();
        }
        public int GetCount()
        {
            return service.IQueryable().Count();
        }
        public DataShareConfigEntity GetForm(string keyValue)
        {
            return service.FindEntity(keyValue);
        }
        //提交
        public void SubmitForm(DataShareConfigEntity dataShareConfigEntity, string keyValue)
        {
            if (!string.IsNullOrEmpty(keyValue))
            {
                dataShareConfigEntity.Modify(keyValue);
                service.Update(dataShareConfigEntity);
            }
            else
            {
                dataShareConfigEntity.Create();
                service.Insert(dataShareConfigEntity);
            }
        }
        //删除
        public void Del(string keyValue)
        {
            service.Delete(a=>a.F_Id==keyValue);
        }
        //更新
        public void Update(DataShareConfigEntity dataShareConfigEntity)
        {
            service.Update(dataShareConfigEntity);
        }

        public DataShareConfigEntity GetEntityByConfigName(string ConfigName)
        {
            var expression = ExtLinq.True<DataShareConfigEntity>();
            if (!string.IsNullOrEmpty(ConfigName))
            {
                expression = expression.And(t => t.ConfigName == ConfigName);
            }
            return service.FindEntity(expression);
        }
    }
}
